package com.swak.boot.config.metrics;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import com.codahale.metrics.MetricRegistry;
import com.swak.Constants;
import com.swak.boot.config.metrics.telnet.CmdPostProcessor;
import com.swak.metrics.impl.CodahaleMetricsFactory;
import com.swak.telnet.Telnet;

/**
 * 指标暴露组件： Telnet 方式
 * 
 * @author lifeng
 * @date 2021/04/14
 */
@Configuration
@ComponentScan(value = { "com.swak.metrics.out.telnet.cmd" })
@ConditionalOnClass({ MetricRegistry.class, CodahaleMetricsFactory.class })
@ConditionalOnProperty(prefix = Constants.ACTUATOR_METRICS, name = "telnet.open", havingValue = "true", matchIfMissing = false)
public class AutoConfigurationMetricsTelnetComponents {

	/**
	 * Cmd 的收集
	 * 
	 * @return
	 */
	@Bean
	public CmdPostProcessor cmdPostProcessor() {
		return new CmdPostProcessor();
	}

	/**
	 * Telnet 管理
	 * 
	 * @return
	 */
	@Bean
	public Telnet telnet() {
		return Telnet.getInstance();
	}
}